package com.erik.ipmonitor.controller;

import com.erik.ipmonitor.model.vo.IpVO;
import com.erik.ipmonitor.service.IndexService;
import com.erik.ipmonitor.utils.FsServletUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * IndexController
 *
 * @author : erik.zhou
 * @date : 2025/07/09/15:56
 * @description :
 */
@Controller
public class IndexController {

    @Autowired
    private IndexService indexService;

    @GetMapping("/")
    public String index() {
        return "index";
    }


    @GetMapping("/api/getIpAddress")
    @ResponseBody
    public IpVO getIpAddress(@RequestParam(value = "finger", required = false) String finger) {
        IpVO ipVO = new IpVO();
        String clientIp = FsServletUtils.getClientIp();
        ipVO.setIp(clientIp);
        indexService.saveIp(clientIp, finger);
        return ipVO;
    }
}
